package com.scrawler.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;



/**  
 * @Description: 描述
 * @author kuntang    
 * @version 1.0  
 * @created 2012-11-2 上午11:41:16 
 * Copyright (c) 2012 sohu,Inc. All Rights Reserved.
 */

public class MysqlConfig {

	private static final Log LOG = LogFactory.getLog(MysqlConfig.class);
	
	/**
	 * 从数据库连接池中获取链接.
	* @return  
	* @see com.sohu.sRank.dao.MysqlConfig#getConnection()
	 */
	public static Connection getConnection(){		
		String url = "jdbc:mysql://localhost:3306/yuqing?useUnicode=true&characterEncoding=UTF-8";
		String user = "root";
		String password = "root";
		Connection conn = null;
		try {
			conn= DriverManager.getConnection(url, user, password);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			LOG.info("get connection from pool error.....",e);
		} 
		return conn;
	}
	
	public static void close(Connection conn,Statement st){
		
		if(st != null){
			try {
				st.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		if(conn != null){
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	
	
    public static void main(String args[]){
    	MysqlConfig mysql = new MysqlConfig();
    	Connection conn = mysql.getConnection();
    	if(conn != null){
    		System.out.println(conn);
    	}
    }


}
